<template>
  <div class="roleAdd">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px">
        <el-form-item class="rolename" label="参数名称" prop="paramName">
            <el-input v-model="ruleForm.paramName"></el-input>
        </el-form-item>
        <el-form-item class="rolename" label="参数值" prop="paramVal">
            <el-input v-model="ruleForm.paramVal"></el-input>
        </el-form-item>
        <el-form-item class="rolename" label="参数模块" prop="paramMode">
            <el-input v-model="ruleForm.paramMode"></el-input>
        </el-form-item>
        <el-form-item class="rolename" label="描    述" prop="description">
            <el-input v-model="ruleForm.description"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" class="save" @click="save('ruleForm')">保存</el-button>
            <el-button class="quxiao" @click="closeLayer">取消</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "roleAdd",
  data() {
    return {
      ruleForm: {
        paramName: "", //参数名,长度3-20,Y
        paramVal: "", //参数值,长度3-32,Y
        paramMode: "", //模块,长度3-20
        description: "" //参数描述,不能超过200
      },
      rules: {
        paramName: [
          { required: true, message: "请输入参数名", trigger: "blur" },
          { min: 3, max: 20, message: "长度在 3 到 20 个字符", trigger: "blur" }
        ],
        paramVal: [
          { required: true, message: "请输入参数值", trigger: "blur" },
          { min: 3, max: 32, message: "长度在 3 到 32 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    //关闭layer弹窗
    closeLayer() {
      layer.closeAll();
    },
    save(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {//验证通过执行方法
          // alert("submit!");
          axios.post(sysparamsURL,{
            paramName: this.ruleForm.paramName,
            paramVal: this.ruleForm.paramVal,
            paramMode: this.ruleForm.paramMode,
            description: this.ruleForm.description
          },{
            headers: { Authorization: appDB.get("userInfo").token },
          })
          .then(res=>{
            let d = res.data;
            if(d.resultCode==0){
              this.$parent.getSystem();//渲染列表
              this.closeLayer();//关闭layer弹窗
            }else{
              layer.msg(d.msg)
            }
          })
          .catch(error => {
            layer.msg("网络错误");
          });
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
.roleAdd {
  width: 80%;
  padding: 50px 10%;
  float: left;
}
.save {
  padding: 8px 40px;
  background: #38b824;
  border-color: #38b824;
  border-radius: 30px;
  float: right;
  margin-left: 30px;
}
.quxiao {
  background: #cecece;
  padding: 8px 40px;
  color: #5a5e66;
  border-radius: 30px;
  float: right;
}
</style>


